#include "gd32f30x.h"
#include "string.h"
#include "stdint.h"
#include "stdio.h"

#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"

#include "lfs.h"
#include "lfs_util.h"

#include "taskLittleFS.h"


TaskHandle_t g_TaskLittleFSHand = NULL;

/* SPI flash 句柄 */
lfs_t g_lfsSpiFlashHandle;
/* 当前待写入Log信息的文件句柄 */
lfs_file_t st_lfsLogWriteHandle;
/* SPI Flash操作函数 */
extern struct lfs_config g_LittlefsSpiFlashCfg;


int8_t cLittlefsSpiFlashInit(void)
{
    int32_t error = 0;

    /* 挂载磁盘 */
    error = lfs_mount(&g_lfsSpiFlashHandle, &g_LittlefsSpiFlashCfg);
    if( error != LFS_ERR_OK )
    {
        /* 格式化、并挂载磁盘 */
        lfs_format(&g_lfsSpiFlashHandle, &g_LittlefsSpiFlashCfg);
        lfs_mount(&g_lfsSpiFlashHandle, &g_LittlefsSpiFlashCfg);
    }

    return error;
}

void vTaskLittleFS(void *pvParameters)
{
    cLittlefsSpiFlashInit();

    while (1)
    {
        vTaskDelay(10);
    }
}
